﻿using Admin2024.Application.Contracts.Role;
using Admin2024.Application.Contracts.User.Dto;
using Admin2024.Domain.DomainService.System.UserService;
using Admin2024.Domain.Entity.System;
using Admin2024.Domain.IDomainService.System.IRoleService;
using Admin2024.Domain.IDomainService.System.IUserService;
using Admin2024.Domain.ObjValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin2024.Application.Role
{
    public class RoleStateService : IRoleStateService
    {
        private readonly IRoleStateManager _roleStateManager;

        public RoleStateService(IRoleStateManager roleStateManager)
        {

            _roleStateManager = roleStateManager;
        }
        public async Task<DomainResult<Guid>> DeleteRole(Guid id)
        {
            var role = await _roleStateManager.DeleteRole(id);

            if (!role.IsSuccess)
            {
                return DomainResult<Guid>.Error(role.Message);
            }
      
            return DomainResult<Guid>.Success(role.Data.Id);
        }

        public  async Task<DomainResult<bool>> DisableRole(Guid id)
        {
            var role = await _roleStateManager.DisableRole(id);

            if (!role.IsSuccess)
            {
                return DomainResult<bool>.Error(role.Message);
            }

            return DomainResult<bool>.Success(role.Data.IsDeleted);
        }

        public async Task<DomainResult<bool>> EnableRole(Guid id)
        {
            var role = await _roleStateManager.EnableRole(id);

            if (!role.IsSuccess)
            {
                return DomainResult<bool>.Error(role.Message);
            }

            return DomainResult<bool>.Success(role.Data.IsActived);
        }
    }
}
